package spring.aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;

/**
 * @author 吴阳基
 * @datetime 2024/1/11 8:46
 */
@Aspect
public class ErrorLogger {
    private static final Logger logger = Logger.getLogger(ErrorLogger.class);

    @AfterThrowing(pointcut = "execution(* spring.service.UserService.*(..))", throwing = "e") // throwing指定异常的变量名，e为异常变量名，可以自定义，但是�
    public void afterThrowing(JoinPoint jp, RuntimeException e) {
        logger.error(jp.getSignature().getName() + "方法异常：" + e);
    }
}
